#!/usr/bin/env bash

source scripts/_var.sh
source scripts/_fn.sh

[ -z "$REMOTE_USER" ] && REMOTE_USER=ec2-user
[ -z "$REMOTE_IP" ] && panic "Must provide REMOTE_IP"

BINARY_FILE=$REPO_DIR/$PROC.$BIN.$HASH.bin

# shellcheck disable=SC2029
ssh "$REMOTE_USER@$REMOTE_IP" "mkdir -p $DEPLOY_TARGET/repo"

rsync -czavh -P "$BINARY_FILE" "$REMOTE_USER@$REMOTE_IP:$DEPLOY_TARGET/repo"

# shellcheck disable=SC2029
ssh "$REMOTE_USER@$REMOTE_IP" "ln -sf repo/$PROC.$BIN.$HASH.bin $DEPLOY_TARGET/$PROC.$BIN.bin"
